package com.carrie.controller;

import com.carrie.model.Goods;
import com.carrie.model.entity.config.Setting;
import com.carrie.service.impl.BagWithGoodsServerImpl;
import com.carrie.tools.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;

/**
 * @author XuHaiLong
 * @since 2025/4/14 16:57
 */
@RestController
@RequestMapping("/api")
public class BagController {
    private static final Logger logger = LoggerFactory.getLogger(BagController.class);
    @Autowired
    private BagWithGoodsServerImpl serverImpl;
    @GetMapping("/getBagWithGoods")
    public Result getBagWithGoods() {
        return Result.success(serverImpl.getAllBageWithGoods());
    }
    @GetMapping("/insertBag")
    public Result insertBag(@RequestParam int bagId, @RequestParam String bagIcon, @RequestParam String bagName) {
        return  serverImpl.insertBag(bagId, bagIcon,bagName);
    }
    @GetMapping("/Settins.json")
    public ResponseEntity<Result> getSettins() {
        ArrayList<Setting> list = new ArrayList<>();
        list.add(new Setting("控制器","/imgs/setting/icons/controller.png"));
        list.add(new Setting("键盘与鼠标","/imgs/setting/icons/key_mouse.png"));
        list.add(new Setting("游戏","/imgs/setting/icons/game.png"));
        list.add(new Setting("视角","/imgs/setting/icons/views.png"));
        list.add(new Setting("画质","/imgs/setting/icons/image.png"));
        list.add(new Setting("声音","/imgs/setting/icons/voice.png"));
        list.add(new Setting("辅助设置","/imgs/setting/icons/helper.png"));
        list.add(new Setting("退出游戏","/imgs/setting/icons/exit.png"));
        return ResponseEntity.ok(Result.success(list));
    }
    @PostMapping(value = "/insertGoodsIntoBag", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public Result insertGoods(
            @RequestParam("bagId") int bagId,
            @RequestParam("image") MultipartFile file,
            @RequestParam("name") String name,
            @RequestParam("level") String level,
            @RequestParam("desc") String desc,
            @RequestParam("summary") String summary,
            @RequestParam("amount") Integer amount
    ){
        logger.info("进入 insertGoods 方法，bagId: {}, name: {}, level: {}, desc: {}, summary: {}, amount: {}",
                bagId, name, level, desc, summary, amount); // 新增日志
        Goods goods = new Goods();
        goods.setName(name);
        goods.setLevel(level);
        goods.setDesc(desc);
        goods.setSummary(summary);
        goods.setAmount(amount);

        return serverImpl.insertGoodsIntoBag(bagId, file, goods);
    }
}
